package com.soufang.soufangdemo.controller;

import com.soufang.soufangdemo.base.ApiResponse;
import com.soufang.soufangdemo.dto.SubwayDTO;
import com.soufang.soufangdemo.dto.SubwayStationDTO;
import com.soufang.soufangdemo.dto.SupportAddressDTO;
import com.soufang.soufangdemo.service.AddressService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/cities")
public class CitiesController {
    private final AddressService addressService;

    public CitiesController(AddressService addressService) {
        this.addressService = addressService;
    }

    @GetMapping
    public ApiResponse<List<SupportAddressDTO>> getSupportCities() {
        return ApiResponse.success(addressService.findAllCities());
    }

    @GetMapping("/{cityEnName}/regions")
    public ApiResponse<List<SupportAddressDTO>> getSupportRegions(@PathVariable String cityEnName) {
        return ApiResponse.success(addressService.findAllRegionsByCityName(cityEnName));
    }

    @GetMapping("/{cityEnName}/subways")
    public ApiResponse<List<SubwayDTO>> getSupportSubways(@PathVariable String cityEnName) {
        return ApiResponse.success(addressService.findAllSubwaysByCityName(cityEnName));
    }

    @GetMapping("/{cityEnName}/subways/{subwayId}/stations")
    public ApiResponse<List<SubwayStationDTO>> getSubwayStations(
            @PathVariable("cityEnName") String cityEnName,
            @PathVariable("subwayId") Long subwayId) {
        return ApiResponse.success(addressService.getStationsByCityEnNameAndSubwayId(cityEnName, subwayId));
    }
}
